PROP_0,
PROP_AUTOSELECT,
PROP_CAN_UNSELECT,
+ PROP_ITEM_TYPE,
+ PROP_MODEL,
+ PROP_N_ITEMS,
PROP_SELECTED,
PROP_SELECTED_ITEM,
- PROP_MODEL,
N_PROPS
};
}
g_list_model_items_changed (G_LIST_MODEL (self), position, removed, added);
+ if (removed != added)
+ g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_N_ITEMS]);
g_object_thaw_notify (G_OBJECT (self));
}
case PROP_CAN_UNSELECT:
g_value_set_boolean (value, self->can_unselect);
break;
+
+ case PROP_ITEM_TYPE:
+ g_value_set_gtype (value, gtk_single_selection_get_item_type (G_LIST_MODEL (self)));
+ break;
+
case PROP_MODEL:
g_value_set_object (value, self->model);
break;
+ case PROP_N_ITEMS:
+ g_value_set_uint (value, gtk_single_selection_get_n_items (G_LIST_MODEL (self)));
+ break;
+
case PROP_SELECTED:
g_value_set_uint (value, self->selected);
break;
FALSE,
G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS);
+ /**
+ * GtkSingleSelection:item-type:
+ *
+ * The type of items. See [method@Gio.ListModel.get_item_type].
+ *
+ * Since: 4.8
+ **/
+ properties[PROP_ITEM_TYPE] =
+ g_param_spec_gtype ("item-type", NULL, NULL,
+ G_TYPE_OBJECT,
+ G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
+
+ /**
+ * GtkSingleSelection:model: (attributes org.gtk.Property.get=gtk_single_selection_get_model org.gtk.Property.set=gtk_single_selection_set_model)
+ *
+ * The model being managed.
+ */
+ properties[PROP_MODEL] =
+ g_param_spec_object ("model", NULL, NULL,
+ G_TYPE_LIST_MODEL,
+ G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
+
+ /**
+ * GtkSingleSelection:n-items:
+ *
+ * The number of items. See [method@Gio.ListModel.get_n_items].
+ *
+ * Since: 4.8
+ **/
+ properties[PROP_N_ITEMS] =
+ g_param_spec_uint ("n-items", NULL, NULL,
+ 0, G_MAXUINT, 0,
+ G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
+
/**
* GtkSingleSelection:selected: (attributes org.gtk.Property.get=gtk_single_selection_get_selected org.gtk.Property.set=gtk_single_selection_set_selected)
*
*/
properties[PROP_SELECTED_ITEM] =
g_param_spec_object ("selected-item", NULL, NULL,
- G_TYPE_OBJECT,
- G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
-
- /**
- * GtkSingleSelection:model: (attributes org.gtk.Property.get=gtk_single_selection_get_model org.gtk.Property.set=gtk_single_selection_set_model)
- *
- * The model being managed.
- */
- properties[PROP_MODEL] =
- g_param_spec_object ("model", NULL, NULL,
- G_TYPE_LIST_MODEL,
- G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
+ G_TYPE_OBJECT,
+ G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
g_object_class_install_properties (gobject_class, N_PROPS, properties);
}
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_SELECTED_ITEM]);
}
g_list_model_items_changed (G_LIST_MODEL (self), 0, n_items_before, 0);
+ if (n_items_before)
+ g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_N_ITEMS]);
}
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_MODEL]);
}
}
+static void
+notify_n_items (GObject *object,
+ GParamSpec *pspec,
+ GString *changes)
+{
+ g_string_append_c (changes, '*');
+}
+
static void
selection_changed (GListModel *model,
guint position,
changes = g_string_new ("");
g_object_set_qdata_full (G_OBJECT(result), changes_quark, changes, free_changes);
g_signal_connect (result, "items-changed", G_CALLBACK (items_changed), changes);
+ g_signal_connect (result, "notify::n-items", G_CALLBACK (notify_n_items), changes);
changes = g_string_new ("");
g_object_set_qdata_full (G_OBJECT(result), selection_quark, changes, free_changes);
g_list_store_remove (store, 3);
assert_model (selection, "1 2 3 5");
- assert_changes (selection, "-3");
+ assert_changes (selection, "-3*");
assert_selection (selection, "");
assert_selection_changes (selection, "");
insert (store, 3, 99);
assert_model (selection, "1 2 3 99 5");
- assert_changes (selection, "+3");
+ assert_changes (selection, "+3*");
assert_selection (selection, "");
assert_selection_changes (selection, "");
splice (store, 3, 2, (guint[]) { 97 }, 1);
assert_model (selection, "1 2 3 97");
- assert_changes (selection, "3-2+1");
+ assert_changes (selection, "3-2+1*");
assert_selection (selection, "");
assert_selection_changes (selection, "");
add (store, 1);
assert_model (selection, "1");
- assert_changes (selection, "+0");
+ assert_changes (selection, "+0*");
assert_selection (selection, "1");
assert_selection_changes (selection, "");
splice (store, 0, 1, (guint[]) { 7, 8, 9 }, 3);
assert_model (selection, "7 8 9");
- assert_changes (selection, "0-1+3");
+ assert_changes (selection, "0-1+3*");
assert_selection (selection, "7");
assert_selection_changes (selection, "");
splice (store, 0, 0, (guint[]) { 5, 6 }, 2);
assert_model (selection, "5 6 7 8 9");
- assert_changes (selection, "0+2");
+ assert_changes (selection, "0+2*");
assert_selection (selection, "7");
assert_selection_changes (selection, "");
g_list_store_remove (store, 2);
assert_model (selection, "5 6 8 9");
- assert_changes (selection, "2-2+1");
+ assert_changes (selection, "2-2+1*");
assert_selection (selection, "8");
assert_selection_changes (selection, "");
splice (store, 2, 2, NULL, 0);
assert_model (selection, "5 6");
- assert_changes (selection, "1-3+1");
+ assert_changes (selection, "1-3+1*");
assert_selection (selection, "6");
assert_selection_changes (selection, "");
g_list_store_remove (store, 0);
assert_model (selection, "2");
- assert_changes (selection, "-0");
+ assert_changes (selection, "-0*");
assert_selection (selection, "2");
assert_selection_changes (selection, "");
g_list_store_remove (store, 0);
assert_model (selection, "");
- assert_changes (selection, "-0");
+ assert_changes (selection, "-0*");
assert_selection (selection, "");
assert_selection_changes (selection, "");
/* we retain the selected item across model changes */
gtk_single_selection_set_model (GTK_SINGLE_SELECTION (selection), m2);
- assert_changes (selection, "0-5+3");
+ assert_changes (selection, "0-5+3*");
assert_selection (selection, "1");
assert_selection_changes (selection, "");
gtk_single_selection_set_model (GTK_SINGLE_SELECTION (selection), NULL);
- assert_changes (selection, "0-3");
+ assert_changes (selection, "0-3*");
assert_selection (selection, "");
assert_selection_changes (selection, "");
gtk_single_selection_set_autoselect (GTK_SINGLE_SELECTION (selection), FALSE);
gtk_single_selection_set_model (GTK_SINGLE_SELECTION (selection), m2);
- assert_changes (selection, "0+3");
+ assert_changes (selection, "0+3*");
assert_selection (selection, "");
assert_selection_changes (selection, "");
/* we retain no selected item across model changes */
gtk_single_selection_set_model (GTK_SINGLE_SELECTION (selection), m1);
- assert_changes (selection, "0-3+5");
+ assert_changes (selection, "0-3+5*");
assert_selection (selection, "");
assert_selection_changes (selection, "");
assert_selection_changes (selection, "4:1");
gtk_single_selection_set_model (GTK_SINGLE_SELECTION (selection), m2);
- assert_changes (selection, "0-5+3");
+ assert_changes (selection, "0-5+3*");
assert_selection (selection, "");
assert_selection_changes (selection, "");